#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : aimix
@File    : load_source_materials_worker.py
@IDE     : PyCharm
@Author  : admin
@Date    : 2025/4/27 17:01
"""

import json
import traceback
from PyQt5.QtCore import QThread, pyqtSignal
from utils.tools import request
from config import Config


class LoadAudioVideoMaterialsWorker(QThread):
    """加载音频视频素材的线程类"""
    result = pyqtSignal(str)
    failed = pyqtSignal(Exception)

    def __init__(self, source, page, headers, parent=None):
        super(LoadAudioVideoMaterialsWorker, self).__init__()
        self.source = source
        self.page = page
        self.headers = headers


    def run(self):
        try:
            url = f"{Config.Host}/api/get/source/materials/"
            data = {
              "src":self.source,
              "ex": 8,
              "page": self.page,
              "type": ""
            }
            response = request(url, method='POST', data=json.dumps(data), headers=self.headers)
            result = response.json()
            self.result.emit(json.dumps(result["data"]))
        except Exception as e:
            self.failed.emit(e)
            traceback.print_exc()
            return